# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：     job
   Description :
   Author :       Flyoung
   date：          2023/9/5
-------------------------------------------------
   Change Activity:
                   2023/9/5:
-------------------------------------------------
"""
from sqlalchemy import Column, Integer, String, Float, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Session

from db.common import with_session, get_session

Base = declarative_base()


class Job(Base):
    __tablename__ = 'job'

    job_id = Column(Integer, primary_key=True, autoincrement=True)
    job_name = Column(String(255), nullable=True)
    city_id = Column(Integer, nullable=True)
    salary_upper_limit = Column(Float, nullable=True)
    salary_lower_limit = Column(Float, nullable=True)
    experience_upper_limit = Column(Float, nullable=True)
    experience_lower_limit = Column(Float, nullable=True)
    company = Column(String(255), nullable=True)
    company_size_upper_limit = Column(Integer, nullable=True)
    company_size_lower_limit = Column(Integer, nullable=True)
    job_score = Column(Float, nullable=True)

    def to_dict(self):
        return {
            'job_id': self.job_id,
            'job_name': self.job_name,
            'city_id': self.city_id,
            'salary_upper_limit': self.salary_upper_limit,
            'salary_lower_limit': self.salary_lower_limit,
            'experience_upper_limit': self.experience_upper_limit,
            'experience_lower_limit': self.experience_lower_limit,
            'company': self.company,
            'company_size_upper_limit': self.company_size_upper_limit,
            'company_size_lower_limit': self.company_size_lower_limit,
            'job_score': self.job_score
        }

    def __init__(self, job_name, city_id, salary_upper_limit, salary_lower_limit,
                 experience_upper_limit, experience_lower_limit, company, company_size_upper_limit,
                 company_size_lower_limit, job_score):
        self.job_name = job_name
        self.city_id = city_id
        self.salary_upper_limit = salary_upper_limit
        self.salary_lower_limit = salary_lower_limit
        self.experience_upper_limit = experience_upper_limit
        self.experience_lower_limit = experience_lower_limit
        self.company = company
        self.company_size_upper_limit = company_size_upper_limit
        self.company_size_lower_limit = company_size_lower_limit
        self.job_score = job_score


def add_job(job):
    session = get_session()
    session.add(job)
    session.commit()
    return job.to_dict()
